package com.bazaaroid.client.web.gwt.partnermodule.client.view.partnerinfo;

import com.bazaaroid.client.web.gwt.partnermodule.client.dto.PartnerInfoDTO;
import com.bazaaroid.client.web.gwt.partnermodule.client.view.common.TitleCommandBar;
import com.bazaaroid.client.web.gwt.partnermodule.client.view.partnerinfo.impl.PartnerInfoTabViewImpl;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PartnerInfoEntryView extends PartnerGenericEntryView<PartnerInfoDTO> {

	private TitleCommandBar titleBar;
	private HTML description = new HTML();
	
	public class EditClickHandler implements ClickHandler {
		@Override
		public void onClick(ClickEvent event) {
			getPartnerInfoTabView().startEditPartnerInfo(PartnerInfoEntryView.this);
		}
	}
	
	public class DeleteClickHandler implements ClickHandler {
		@Override
		public void onClick(ClickEvent event) {
			if(Window.confirm("Are you sure you wand to delete '" + getPartnerGenericDTO().getName() + "'?")) {
				getPartnerInfoTabView().getPartnerInfoViewHandler().onPartnerGenericEntryDeleted(getPartnerGenericDTO());
				removeFromParent();
			}
		}
	}
	
	public PartnerInfoEntryView(PartnerInfoTabViewImpl partnerInfoTabView, PartnerInfoDTO partnerInfoDTO) {
		super(partnerInfoTabView, partnerInfoDTO);
		
		VerticalPanel partnerInfoViewPanel = new VerticalPanel();
		initWidget(partnerInfoViewPanel);
		
		titleBar = new TitleCommandBar(partnerInfoDTO.getName());
		titleBar.addCommand("edit", new EditClickHandler());
		titleBar.addCommand("delete", new DeleteClickHandler());
		partnerInfoViewPanel.add(titleBar);
		partnerInfoViewPanel.add(description);
		partnerInfoViewPanel.setStyleName("partnerInfoPanel");
		description.setStyleName("partnerInfoDescription");
		//titleBar.addStyleName("");
		update();
	}
	
	public void update() {
		titleBar.setTitle(getPartnerGenericDTO().getName());
		description.setHTML(getPartnerGenericDTO().getDescription());
	}

}
